package com.community.charge.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.enums.BusinessType;
import com.community.charge.domain.ChargeItem;
import com.community.charge.service.IChargeItemService;
import com.community.common.utils.poi.ExcelUtil;
import com.community.common.core.page.TableDataInfo;

/**
 * itemaController
 * 
 * @author mdh
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/charge/itema")
public class ChargeItemController extends BaseController
{
    @Autowired
    private IChargeItemService chargeItemService;

    /**
     * 查询收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChargeItem chargeItem)
    {
        startPage();
        List<ChargeItem> list = chargeItemService.selectChargeItemList(chargeItem);
        return getDataTable(list);
    }

    /**
     * 导出收费项目列表
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:export')")
    @Log(title = "收费项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChargeItem chargeItem)
    {
        List<ChargeItem> list = chargeItemService.selectChargeItemList(chargeItem);
        ExcelUtil<ChargeItem> util = new ExcelUtil<ChargeItem>(ChargeItem.class);
        util.exportExcel(response, list, "itema数据");
    }

    /**
     * 获取收费项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:query')")
    @GetMapping(value = "/{chargeItemId}")
    public AjaxResult getInfo(@PathVariable("chargeItemId") Long chargeItemId)
    {
        return success(chargeItemService.selectChargeItemByChargeItemId(chargeItemId));
    }

    /**
     * 新增收费项目
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:add')")
    @Log(title = "收费项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChargeItem chargeItem)
    {
        return toAjax(chargeItemService.insertChargeItem(chargeItem));
    }

    /**
     * 修改收费项目
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:edit')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChargeItem chargeItem)
    {
        return toAjax(chargeItemService.updateChargeItem(chargeItem));
    }

    /**
     * 删除收费项目
     */
    @PreAuthorize("@ss.hasPermi('charge:itema:remove')")
    @Log(title = "收费项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargeItemIds}")
    public AjaxResult remove(@PathVariable Long[] chargeItemIds)
    {
        return toAjax(chargeItemService.deleteChargeItemByChargeItemIds(chargeItemIds));
    }

    //点击禁用按钮禁用
    @PostMapping("/disable/{id}")
    @PreAuthorize("@ss.hasPermi('charge:itema:disable')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    public AjaxResult disable(@PathVariable Integer id){
        return toAjax(chargeItemService.disable(id));
    }

    //点击启用按钮启用
    @PostMapping("/enable/{id}")
    @PreAuthorize("@ss.hasPermi('charge:itema:enable')")
    @Log(title = "收费项目", businessType = BusinessType.UPDATE)
    public AjaxResult enable(@PathVariable Integer id){
        return toAjax(chargeItemService.enable(id));
    }

    //绑定收费项目下拉框
    @GetMapping("/getChargeItem")
    public AjaxResult getChargeItem(){
        return AjaxResult.success(chargeItemService.getChargeItem());
    }

}
